<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h1>{{msg}}</h1>
      <h2>接受组件传递过来的值:{{getMsg}}</h2>
      <home title='我是homed的标题'></home>

      <home :data='data' @send-to-parent='getData'></home>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>

        Vue.component("home",{
            props:['title','data'],
            data(){
                return {
                    mymsg:'儿子',
                }
            },
            template:
            `
            <div>
            <h2>{{title}}</h2>
            <h3>{{data}}</h3>
            <button  @click='sendData'>  点击发送成绩给老爸</button> 
            
            </div>
            `,
            methods:{
                sendData(){
                    this.$emit('send-to-parent',this.mymsg)
                }
            }
        })
      var vm = new Vue({
        el: "#app",
        data: {
          msg: "vue",
          data:'我是父亲',
          getMsg:''
        },
        methods: {
            getData(data){
                console.log(data);
                this.getMsg = data
            }

        },
      });
    </script>
  </body>
</html>
